import os
import re

caseList = []

class casen:
    def __init__(self,file,name):
        self.file = file
        self.name = name
    
    def __str__(self):
        return f'{self.file}\t-->\t{self.name}'



def readfile(filename:str)->None:
    with open(filename,'r',encoding='gbk',errors='replace') as f:
        lines = f.readlines()
    for line in lines:
        if line.startswith('CASE'):
            casename = re.findall(r'\((.*?)\)',line)
            caseList.append(casen(filename,casename[0]))

def dirlist(dirName:str):
    filelist = os.listdir(dirName)
    for casefile in filelist:
        if casefile.endswith('.c'):
            tmppath = dirName + '\\' + casefile
            readfile(tmppath)

# readfile('CallBack\\CASE\\BaseCase.c')
caseDir = "CallBack\\CASE"

dirlist(caseDir)

sacefile = 'caseList.txt'
#save
with open(sacefile,'w') as ff:
    for n in caseList:
        # print(n)
        ff.write(n.__str__() + '\r\n')
